import sqlite3
# --------------------------------创建表并插入数据----------------------------------------------------------------------
conn = sqlite3.connect("sql.db")
cur = conn.cursor()
cur.execute("create table user (id varchar(20) primary key, name varchar(20))")
cur.execute("insert into user values (\"1\", \"Jerry\")")
print(cur.rowcount)
cur.close()
conn.commit()
conn.close()
# --------------------------------查询数据------------------------------------------------------------------------------
conn2 = sqlite3.connect("sql.db")
cur2 = conn2.cursor()
cur2.execute("select * from user")
print(cur2.fetchall())
cur2.close()
conn2.close()
# cursor.execute('select * from user where name=? and pwd=?', ('abc', 'password'))